package com.flower.controller;

import com.flower.model.dto.ManagePageQueryDto;
import com.flower.model.dto.UserDto;
import com.flower.model.dto.UserPasswordDTO;
import com.flower.result.PageResult;
import com.flower.result.Result;
import com.flower.service.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.flower.model.entity.Manager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName ManagerController
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/12 16:12
 *@Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/manager")
@Api(tags = "管理员管理")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> getManagerList(ManagePageQueryDto managePageQueryDto) {
        log.info("分页查询：{}", managePageQueryDto);
        PageResult pageResult = managerService.pageQuery(managePageQueryDto);
        return Result.success(pageResult);
    }

//    @PostMapping
//    @ApiOperation("修改管理员信息")
//    public Result<String> updateManager(@RequestBody UserDto userDto) {
//        log.info("修改管理员信息：{}", userDto);
//        managerService.updateManager(userDto);
//        return Result.success("保存成功");
//    }

    @PostMapping("/update")
    @ApiOperation("更新状态接口")
    public Result<String> updateEnable(@RequestBody UserDto userDto) {
        log.info("更新状态：{}", userDto);
        managerService.updateEnable(userDto);
        return Result.success("操作成功");
    }

    @DeleteMapping("/{adid}")
    @ApiOperation("删除单个管理员")
    public Result<String> deleteManager(@PathVariable Integer adid) {
        log.info("删除管理员：{}", adid);
        managerService.deleteManager(adid);
        return Result.success("删除成功");
    }

    @DeleteMapping("del/batch")
    @ApiOperation("批量删除管理员")
    public Result<String> deleteManagerList(@RequestBody List<Integer> ids) {
        log.info("批量删除管理员：{}", ids);
        managerService.deleteManagerList(ids);
        return Result.success("批量删除成功");
    }
//    @GetMapping
//    @ApiOperation("获取所有管理员")
//    public Result getAllManager(){
//        return Result.success("managerService.getAllManager()");
//    }

    @GetMapping("/flagisbuy")
    @ApiOperation("查询采购人接口")
    public Result<PageResult> getAllManagerBuy(ManagePageQueryDto managePageQueryDto){
        log.info("查询采购人接口：{}", managePageQueryDto);
        PageResult pageResult = managerService.getAllManager(managePageQueryDto);
        return Result.success(pageResult);
    }
    @GetMapping("/flagissale")
    @ApiOperation("查询申请人接口")
    public Result<PageResult> getAllManagerSale(ManagePageQueryDto managePageQueryDto){
        log.info("查询申请人接口：{}", managePageQueryDto);
        PageResult pageResult = managerService.getAllManager(managePageQueryDto);
        return Result.success(pageResult);
    }
    @GetMapping("/flagisadmin")
    @ApiOperation("查询管理人员接口")
    public Result<PageResult> getAllManagerAdmin(ManagePageQueryDto managePageQueryDto){
        log.info("查询管理人员接口：{}", managePageQueryDto);
        PageResult pageResult = managerService.getAllManager(managePageQueryDto);
        return Result.success(pageResult);
    }

    @GetMapping("/adname/{adname}")
    public Result findOne(@PathVariable String adname){
        Manager manager = managerService.getByAdname(adname);
        return Result.success(manager);
    }
    @PostMapping
    public Result save(@RequestBody Manager manager){
        log.info("保存管理员：{}", manager);
        managerService.Update(manager);
        return Result.success("保存成功");
    }
    @PostMapping("/password")
    public Result updatePassword(@RequestBody UserPasswordDTO userPasswordDTO){
        log.info("修改密码：{}", userPasswordDTO);
        managerService.UpdatePwd(userPasswordDTO);
        return Result.success("修改成功");
    }
}
